﻿#region Namespaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using NGenORM.Library.Enum;
using NGenORM.Library.Code;

#endregion

namespace NGenORM.Library.Util
{
	public abstract class ConnectionFactory
	{

		#region "Variables"
		private static string SourceDatabase = null; //producao / teste / local
		#endregion

		#region Objects
		protected static SqlConnection connection { get; set; }
		#endregion

		#region Attributes
        public string Datasource { get; set; }
        public string Database { get; set; }
        public string UserID { get; set; }
        public string Password { get; set; }
		public bool IntegratedSecurity { get; set; }
        public Project Project { get; set; }
		#endregion

		private ConnectionFactory ConnectionFactoryFactory() {

			switch (Project.DBServerType) {
				case DBServerType.MySQL:
					return new ConnectionFactoryMySQL();
				case DBServerType.SQLServer:
					return new ConnectionFactorySQLServer();
				case DBServerType.Oracle:
					return new ConnectionFactoryOracle();
				default:
					return null;
			}

		}

		/// <summary>
		/// Instancia um objeto de Conexão
		/// </summary>
		/// <param name="Conexao">Objeto de Conexão</param>
		/// <remarks></remarks>
		public abstract SqlConnection CreateConnection();

		/// <summary>
		/// Abre a Conexão
		/// </summary>
		/// <param name="Conexao">Objeto de Conexão do tipo SqlConnection</param>
		/// <remarks></remarks>
		public abstract bool OpenConnection();

		/// <summary>
		/// Fecha a Conexão
		/// </summary>
		/// <param name="Conexao">Objeto de Conexão do tipo SqlConnection</param>
		/// <remarks></remarks>
		public abstract bool CloseConnection();

		public abstract bool TestConnection();

	}
}
